package org.example.campus_sys_backend.controller;

import org.example.campus_sys_backend.model.ActivityInfo;
import org.example.campus_sys_backend.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/activity")

public class ActivitiesController {
   @Autowired
    public ActivityService activityService;

    @RequestMapping("/add")
    public boolean addActivity(ActivityInfo activityInfo){
       if (activityInfo!=null){
           activityService.insertActivity(activityInfo);
           return true;
       }
       return false;
   }
     @RequestMapping("/update")
    public boolean updActivity(Integer id, String name, String category, String title, String creator, String abs,
                               String detailedDesc, String status,
                               @DateTimeFormat(pattern = "yyyy-MM-dd") Date createdTime,
                               @DateTimeFormat(pattern = "yyyy-MM-dd") Date archivedTime,
                               String picUrls, @DateTimeFormat(pattern = "yyyy-MM-dd")Date startTime,
                               @DateTimeFormat(pattern = "yyyy-MM-dd")Date endTime){
        if(id > 0 && activityService.queryActivityById(id) !=null){
            activityService.updateActivity(id,name,category,title,creator,abs,detailedDesc,status,createdTime,archivedTime,picUrls,startTime,endTime);
            return true;
        }
         System.out.println("参数输入不合法");
        return false;
    }
    @RequestMapping("/select")
    public List<ActivityInfo> selActivity (String status, String name){
        if (status != null || name != null){
          return  activityService.selectActivity(status,name);

        }
        System.out.println("参数输入不合法");
        return null;
    }
    @RequestMapping("/open")
    public boolean opeActivity(Integer id, String status){
        if (id > 0 || status != null){
            activityService.openActivity(id,status);
            return true;
        }
        return false;
    }


}
